package com.haima.sage.bigdata.api.frame.datatype;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.haima.sage.bigdata.api.common.Constants;
import com.haima.sage.bigdata.api.frame.datatype.impl.BooleanDataTypeService;
import com.haima.sage.bigdata.api.frame.datatype.impl.DateDataTypeService;
import com.haima.sage.bigdata.api.frame.datatype.impl.DateLongDataTypeService;
import com.haima.sage.bigdata.api.frame.datatype.impl.DateStringDataTypeService;
import com.haima.sage.bigdata.api.frame.datatype.impl.DoubleDataTypeService;
import com.haima.sage.bigdata.api.frame.datatype.impl.FloatDataTypeService;
import com.haima.sage.bigdata.api.frame.datatype.impl.IntDataTypeService;
import com.haima.sage.bigdata.api.frame.datatype.impl.LongDataTypeService;
import com.haima.sage.bigdata.api.frame.datatype.impl.StringDataTypeService;

public class DataTypeServiceFactory {
	private static final Logger LOG = LogManager.getLogger(DataTypeServiceFactory.class);

	public static DataTypeService<?> getInstance(DataType type) {
		return getInstance(type, Constants.DATE_PATTERN);
	}

	public static DataTypeService<?> getInstance(final DataType type, String pattern) {
		if (type != null) {
			switch (type) {
			case Int:
				return new IntDataTypeService();
			case Long:
				return new LongDataTypeService();
			case Text:
				return new StringDataTypeService();
			case Date:
				return new DateDataTypeService(pattern);
			case LongDate:
				return new DateLongDataTypeService(Constants.DATE_PATTERN);
			case TextDate:
				return new DateStringDataTypeService(pattern, Constants.DATE_PATTERN);
			case Float:
				return new FloatDataTypeService();
			case Double:
				return new DoubleDataTypeService();
			case Boolean:
				return new BooleanDataTypeService();
			default:
				LOG.warn("unknown data type:{}, so not tran data type", type);
			}
		}
		return null;
	}

}
